package net.flydy.ywxcx.wxcloudrun.common;

import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author flydy
 */
public class MyDateUtils {

    public final static String FORMAT_DATE = "yyyy-MM-dd";
    public final static String FORMAT_TIME = "HH:mm";
    public final static String FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm";
    public final static String FORMAT_MONTH_DAY_TIME = "MM月dd日 HH:mm";
    public final static String FORMAT_FULL_DATE_TIME_WITH_SYMBOL = "yyyy-MM-dd HH:mm:ss";
    public final static String FORMAT_FULL_DATE_TIME_WITH_SYMBOL_MICROSECONDS = "yyyy-MM-dd HH:mm:ss:SSS";
    public final static String FORMAT_FULL_DATE_TIME_NO_SYMBOL = "yyyyMMddHHmmss";
    public final static String FORMAT_FULL_DATE_TIME_WITH_MILLS_NO_SYMBOL = "yyyyMMddHHmmssSSS";
    public final static String FORMAT_FULL_DATE_TIME_WITH_HOUR_NO_SYMBOL="yyyyMMddHH";

    public static final ConcurrentHashMap<String, DateTimeFormatter> DateTimeFormatters = new ConcurrentHashMap<>();
    static {
        DateTimeFormatters.put(FORMAT_MONTH_DAY_TIME, DateTimeFormatter.ofPattern(FORMAT_MONTH_DAY_TIME));
        DateTimeFormatters.put(FORMAT_FULL_DATE_TIME_WITH_SYMBOL, DateTimeFormatter.ofPattern(FORMAT_FULL_DATE_TIME_WITH_SYMBOL));
        DateTimeFormatters.put(FORMAT_FULL_DATE_TIME_WITH_SYMBOL_MICROSECONDS, DateTimeFormatter.ofPattern(FORMAT_FULL_DATE_TIME_WITH_SYMBOL_MICROSECONDS));
        DateTimeFormatters.put(FORMAT_FULL_DATE_TIME_NO_SYMBOL, DateTimeFormatter.ofPattern(FORMAT_FULL_DATE_TIME_NO_SYMBOL));
        DateTimeFormatters.put(FORMAT_FULL_DATE_TIME_WITH_MILLS_NO_SYMBOL, DateTimeFormatter.ofPattern(FORMAT_FULL_DATE_TIME_WITH_MILLS_NO_SYMBOL));
        DateTimeFormatters.put(FORMAT_FULL_DATE_TIME_WITH_HOUR_NO_SYMBOL, DateTimeFormatter.ofPattern(FORMAT_FULL_DATE_TIME_WITH_HOUR_NO_SYMBOL));
    }

    /**
     * 根据format解析
     * @param dateStr
     * @param format 格式不合法会抛出运行时异常
     * @return
     */
    public static Date parseDate(String dateStr, String format) {
        return DateUtil.parse(dateStr, format);
    }

    public static String constellation2(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
       return DateUtil.getZodiac(date.getMonth() + 1, date.getDay() + 1);
    }


    /*** 计算星座* CSDN程忆难** @param birthday* @return*/
    public static String constellation(Date birthdayDate) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("Mdd");
        String format = simpleDateFormat.format(birthdayDate);
        int date = Integer.parseInt(format);
        if (date >= 121 && date <= 219) {
            return "水瓶座";
        } else if (date >= 220 && date <= 320) {
            return "双鱼座";
        } else if (date >= 321 && date <= 420) {
            return "白羊座";
        } else if (date >= 421 && date <= 521) {
            return "金牛座";
        } else if (date >= 522 && date <= 621) {
            return "双子座";
        } else if (date >= 622 && date <= 722) {
            return "巨蟹座";
        } else if (date >= 723 && date <= 823) {
            return "狮子座";
        } else if (date >= 824 && date <= 923) {
            return "处女座";
        } else if (date >= 924 && date <= 1023) {
            return "天秤座";
        } else if (date >= 1024 && date <= 1122) {
            return "天蝎座";
        } else if (date >= 1123 && date <= 1221) {
            return "射手座";
        } else {
            return "魔蝎座";
        }
    }

}
